package com.lanxiao.cloud.modules.dept.domain.model;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lanxiao.cloud.common.mybatis.basic.BaseEntity;
import java.util.List;
import java.util.Objects;

/**
 * @author ：qiaoliang
 * @date ：2021-10-26
 */
@TableName(value = "sys_dept", autoResultMap = true)
public class Dept extends BaseEntity<Long, Long> {

  /**名称**/
  private String name;
  /**父级ID**/
  private Long parentId;
  /**父级ID集合**/
  private String parentIds;

  /**
   *  填充父级ID
   *
   * @author ：qiaoliang
   * @param parent : 父级权限
   * @date 2021-10-22 11:51
   */
  public void fillParentIds(Dept parent) {
    if (Objects.nonNull(parent)) {
      String parentIds = parent.getParentIds();
      final List<Long> list = JSONUtil.toList(JSONUtil.parseArray(parentIds), Long.class);
      list.add(parent.getId());
      this.setParentIds(JSONUtil.toJsonStr(list));
    }
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Long getParentId() {
    return parentId;
  }

  public void setParentId(Long parentId) {
    this.parentId = parentId;
  }

  public String getParentIds() {
    return parentIds;
  }

  public void setParentIds(String parentIds) {
    this.parentIds = parentIds;
  }
}
